package com.four.reimbursemanage.dao;

import com.four.reimbursemanage.entity.CondolenceApply;
import com.four.reimbursemanage.entity.Dailyapply;
import com.four.reimbursemanage.entity.Payapply;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

@Mapper
public interface CondolenceApplyMapper {
    /**
     * 查询慰问金报销申请列表
     */    @Select("<script>" +
            "SELECT id,apply_department as applyDepartment,transactor,payee,bank,accuount_number as accuountNumber,pay_big as payBig,pay_small as paySmall,reason,state FROM condolence_apply" +
            "<where>" +
            "    <if test=\"applyDepartment != null\">" +
            "      and apply_department = #{applyDepartment}" +
            "   </if>" +
            "    <if test=\"payee != null\">" +
            " <bind name=\"Key\" value=\"'%'+payee+'%'\"/>" +
            "        payee like #{Key} " +
            "    </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<CondolenceApply> getall(int start, int size,String applyDepartment,
                                        String payee,Integer state);
    /**
     * 查询本人慰问金报销申请列表
     */    @Select("<script>" +
            "SELECT id,number,apply_department as applyDepartment,transactor,payee,bank,accuount_number as accuountNumber,pay_big as payBig,pay_small as paySmall,reason,state FROM condolence_apply" +
            "<where>" +
            "    <if test=\"applyDepartment != null\">" +
            "      and apply_department = #{applyDepartment}" +
            "   </if>" +
            "    <if test=\"payee != null\">" +
            " <bind name=\"Key\" value=\"'%'+payee+'%'\"/>" +
            "        payee like #{Key} " +
            "    </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<CondolenceApply> getUser(int start, int size,String applyDepartment,
                                        String payee,Integer state,String number);
    /*分页*/
    @Select("<script>" +
            "SELECT count(*) FROM condolence_apply" +
            "<where>" +
            "    <if test=\"payee != null\">" +
            " <bind name=\"Key\" value=\"'%'+payee+'%'\"/>" +
            "        payee like #{Key} " +
            "    </if>" +
            "    <if test=\"applyDepartment != null\">" +
            "      and apply_department = #{applyDepartment}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countCondolenceApply(String applyDepartment,
                               String payee,Integer state);
    /*本人分页*/
    @Select("<script>" +
            "SELECT count(*) FROM condolence_apply" +
            "<where>" +
            "    <if test=\"payee != null\">" +
            " <bind name=\"Key\" value=\"'%'+payee+'%'\"/>" +
            "        payee like #{Key} " +
            "    </if>" +
            "    <if test=\"applyDepartment != null\">" +
            "      and apply_department = #{applyDepartment}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countCondolenceApplyUser(String applyDepartment,
                                    String payee,Integer state, String number);
    /**
     * 新增慰问金申请
     * @return 结果
     */
    @Insert("insert into condolence_apply (number,apply_department,transactor,payee,bank,accuount_number,pay_big,pay_small,reason,state)" +
            "values (#{number},#{applyDepartment},#{transactor},#{payee},#{bank},#{accuountNumber},#{payBig},#{paySmall},#{reason},4)")
    public int insertComdolenceapply(CondolenceApply condolenceApply);

    /**
     * 修改慰问金申请
     * @return 结果
     */
    @Update("<script>" +
            "  update condolence_apply" +
            "        <set>" +
            "            <if test=\"null != applyDepartment\"> " +
            "                apply_department = #{applyDepartment}," +
            "            </if>" +
            "            <if test=\"null != transactor\"> " +
            "                transactor = #{transactor}," +
            "            </if>" +
            "            <if test=\"null != payee\"> " +
            "                payee = #{payee}," +
            "            </if>" +
            "            <if test=\"null != bank\"> " +
            "                bank = #{bank}," +
            "            </if>" +
            "            <if test=\"null != accuountNumber\"> " +
            "                accuount_number = #{accuountNumber}," +
            "            </if>" +
            "            <if test=\"null != payBig\"> " +
            "                pay_big = #{payBig}," +
            "            </if>" +
            "            <if test=\"null != paySmall\"> " +
            "                pay_small = #{paySmall}," +
            "            </if>" +
            "            <if test=\"null != reason\"> " +
            "                reason = #{reason}," +
            "            </if>" +
            "            <if test=\"null != state\"> " +
            "                state = #{state}," +
            "            </if>" +
            "        </set>" +
            "        where id = #{id}" +
            "</script>")
    public int updateCondolenceApply(CondolenceApply condolenceApply);


    /*修改审批状态*/
    @Update("<script>" +
            "update  condolence_apply " +
            "        <set>" +
            "            <if test=\"null!= state\">" +
            "                state =#{state}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int updateStateById(CondolenceApply condolenceApply);

}
